﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using 聚欣订单分析.PublicClass;

namespace 聚欣订单分析
{
    public partial class eqType : System.Web.UI.Page
    {
        PLSQLClass pl = new PLSQLClass();
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnParent_Click(object sender, EventArgs e)
        {
            gvParentType.AddNewRow();
        }

        protected void ASPxAddType_Click(object sender, EventArgs e)
        {
            gvepType.AddNewRow();
        }

        protected void gvParentType_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
        {
            if (e.NewValues["TypeName"] == null)
            {
                e.RowError = "名称不能为空！";
                return;
            }
        }

        protected void gvepType_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
        {
            if (e.NewValues["TypeName"] == null)
            {
                e.RowError = "名称不能为空！";
                return;
            }
            if (e.NewValues["ParentID"] == null)
            {
                e.RowError = "请选择上级！";
                return;
            }
        }

        protected void gvParentType_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            string id = e.Keys[0].ToString();
            string strSQL = "select count(*) from tbl_epType where ParentID=" + id;
            if (pl.SqlBind(strSQL).Rows[0][0].ToString() != "0")
            {
                throw new Exception("大类下面存在小类，无法删除！");
            }
        }

        protected void gvepType_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
        {
            string id = e.Keys[0].ToString();
            string strSQL = "select count(*) from tbl_product where TypeID=" + id;
            if (pl.SqlBind(strSQL).Rows[0][0].ToString() != "0")
            {
                throw new Exception("小类下面存在商品，无法删除！");
            }
        }
    }
}
